/*
 *  MeshInstance.cpp
 *  SypXIPhone
 *
 *  Created by Luv Khemani on 5/14/10.
 *  Copyright 2010 Luv Khemani. All rights reserved.
 *
 */
#ifdef SYPX_MEMCHECK
#include "mmgr.h"
#endif

#include "MeshInstance.h"
#include "Texture.h"
#include "Mesh.h"
#include "Sprite.h"
#include "Engine.h"

namespace SypX
{
	MeshInstance::MeshInstance():mesh(0),tex(0)
	{
		
	}
	
	MeshInstance::~MeshInstance()
	{		
		if(mesh)
		{//if we have a previous mesh
			mesh->removeRef();
		}
		if(tex)
		{
			tex->removeRef();
		}
	}


	void MeshInstance::useMesh(Mesh* m)
	{
		if(mesh)
		{							//if we have a previous mesh
			mesh->removeRef();
		}
		
		mesh = m;
		
		if(m)
		{//Ensure m is not null
			m->addRef();
		}

	}

	void MeshInstance::update()
	{
	}

	void MeshInstance::useTexture(Texture* t)
	{
		if(tex)
		{							//if we have a previous texture
			tex->removeRef();		//ubind it
		}

		tex = t;

		if(t)
		{
			t->addRef();			//Add reference
		}
	}
	
	Mesh* MeshInstance::getMesh()
	{
		return mesh;
	}

	Texture* MeshInstance::getTexture()
	{
		return tex;
	}
}